package com.fau.fm.servlet;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.fau.fm.security.MySecurityMetadataSource;

/**
 * @desc 权限分配后刷新角色资源
 * @author kangyj
 * @datetime 2015年3月24日,下午5:07:54
 */
@WebServlet("/refresh-role")
public class RefreshRoleServlet extends HttpServlet {
    
	private static final long serialVersionUID = -4401865262464872353L;
	
	private MySecurityMetadataSource mySecurityMetadataSource;
	
    public RefreshRoleServlet() {
        super();
    }

    /**
     * @desc 刷新角色资源
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @author kangyj
     * @datetime 2015年3月24日,下午5:46:38
     */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletContext servletContext = this.getServletContext();  
        WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        mySecurityMetadataSource = (MySecurityMetadataSource) context.getBean("mySecurityMetadataSource");
		mySecurityMetadataSource.flush();
		System.out.println("请求收到");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
